package sg.edu.nus.iss.billing.service.login;

import java.util.ArrayList;

import sg.edu.nus.iss.billing.common.exception.BadDaoCallException;
import sg.edu.nus.iss.billing.common.exception.BadDbCallException;
import sg.edu.nus.iss.billing.exception.customer.InvalidCustomerDataException;
import sg.edu.nus.iss.billing.service.account.AccountImpl;
import sg.edu.nus.iss.billing.service.customer.CustomerServiceImpl;
import sg.edu.nus.iss.billing.service.customer.ICustomerService;
import sg.edu.nus.iss.billing.service.subscription.ISubscription;
import sg.edu.nus.iss.billing.service.subscription.SubscriptionImpl;
import sg.edu.nus.iss.billing.vo.account.AccountVO;
import sg.edu.nus.iss.billing.vo.customer.CustomerVO;
import sg.edu.nus.iss.billing.vo.login.LoginVO;
import sg.edu.nus.iss.billing.vo.subscription.SubscriptionVO;


public class Administrator extends CallAgent{
	
	private ICustomerService customerService;
	private AccountImpl acctImpl;
	private ISubscription subscriptionImpl;
	
	public Administrator(LoginVO loginVO) {
		super(loginVO);
		
	}

	public String  registerCustomer(CustomerVO customerVO) throws BadDaoCallException, Exception{
		customerService = new CustomerServiceImpl();
		AccountVO accountVO = new AccountVO();
		
		String accNo = customerService.registerCustomer(customerVO);
		accountVO.setAccountNo(accNo);
		accountVO.setNric(customerVO.getNric());
		acctImpl = new AccountImpl();
		acctImpl.createAccount(accountVO);
		
		if(accountVO.getListSubscriptionVO()!=null) {
		subscriptionImpl = new SubscriptionImpl(accountVO.getAccountNo());
		subscriptionImpl.createSubscriptions((ArrayList<SubscriptionVO>)accountVO.getListSubscriptionVO());
		}
		
		System.out.println("Account No:: "+accNo+" for Customer Nric::"+customerVO.getNric()+" is successfully created");
		return accNo;
	}
	
	public void updateCustomerDetails(CustomerVO customerVO){
		customerService = new CustomerServiceImpl();
		customerService.updateCustomerDetail(customerVO);

	}
	
//	public void deRegisterCustomer(CustomerVO customerVO){
//		customerService = new CustomerServiceImpl();
//		customerService.deregisterCustomer(customerVO);
//	}
	
//	public void registerSubscription(SubscriptionVO subcribedPlanVO){
//		
//	}
	public void deregisterAccount(String nric, String status) throws BadDbCallException{
		deregisterAccount(nric, null, status);
	}
	
	public void deregisterAccount(String nric, AccountVO avo, String status) throws BadDbCallException{
		acctImpl.deregisterAccount(nric, avo, status);
	}
	
	public void modifySubscription(AccountVO accountVO) throws BadDbCallException{
		
		acctImpl = new AccountImpl();
		acctImpl.modifyAccount(accountVO);
	}
	
	public AccountVO getAccountDetailsByAccountNumber(String accountNumber){
		acctImpl = new AccountImpl();
		AccountVO accountVO  = acctImpl.getAccountDetailsByAccountNumber(accountNumber);
		return accountVO;
		
	}
	
	public AccountVO getAccountDetailsByNric(String Nric){
		acctImpl = new AccountImpl();
		AccountVO accountVO  = acctImpl.getAccountDetailsByNric(Nric);
		return accountVO;
		
	}

}
